class Solution(object):
    def removeLeafNodes(self, root, target):
        def dfs(node):
            if node.left:
                node.left = dfs(node.left)
            if node.right:
                node.right = dfs(node.right)
            if not node.left and not node.right:
                if node.val == target:
                    return None
            return node
        return dfs(root)
